package com.parenting.controller;


import cn.hutool.core.bean.BeanUtil;
import com.parenting.entities.SystemUserDO;
import com.parenting.oauth2.config.AuthUtil;
import com.parenting.request.AddExtractPasswordRequest;
import com.parenting.request.ShopUserUpdateRequest;
import com.parenting.request.UpdateExtractPasswordRequest;
import com.parenting.request.UserUpdatePasswordRequest;
import com.parenting.response.SystemUserResponse;
import com.parenting.service.SystemUserService;
import com.parenting.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "个人设置", description = "提供个人设置，密码修改、提现密码（增加、修改）")
@RequestMapping("/settings")
@Slf4j
public class PersonalSettingsController {

    @Autowired
    private SystemUserService systemUserService;
    /**
     * 修改密码
     * @param req
     * @return
     */
    @ApiOperation("修改密码")
    @PostMapping("updatePws")
    public Result updatePassword(@RequestBody UserUpdatePasswordRequest req){
        systemUserService.updatePassword(req);
        return Result.buildSuccess();
    }

    /****
     * 修改提现密码
     * @param updateExtractPasswordRequest  修改内容
     * @return
     */
    @ApiOperation("修改提现密码")
    @PostMapping("updateEPws")
    public Result updateExtractPassword(@RequestBody UpdateExtractPasswordRequest updateExtractPasswordRequest){

        return  systemUserService.updateExtractPassword(updateExtractPasswordRequest, AuthUtil.getUserInfo().getId());
    }


    /****
     * 设置提现密码
     * @param extractPasswordRequest
     * @return
     */
    @ApiOperation("设置提现密码")
    @PostMapping("saveEPws")
    public Result saveExtractPassword(@RequestBody AddExtractPasswordRequest extractPasswordRequest){
        log.info("设置提现密码 saveExtractPassword ==== { }",extractPasswordRequest.toString());
        return  systemUserService.saveExtractPassword(extractPasswordRequest,AuthUtil.getUserInfo().getId());
    }

    /***
     * 个人设置
     * @param request
     * @return
     */
    @ApiOperation("个人设置")
    @PostMapping("settings")
    public Result updatePersonalSettings(@RequestBody ShopUserUpdateRequest request){
        request.setId(AuthUtil.getUserInfo().getId());
        systemUserService.updateUser(request);
        return  Result.buildSuccess();
    }

    /**
     * 获得当前登录用户详情
     * @return
     */
    @ApiOperation("获得当前登录用户详情")
    @GetMapping("getUserInfo")
    public Result<SystemUserResponse> findUserByUserId(){
        SystemUserDO byId = systemUserService.getById(AuthUtil.getUserInfo().getId());
        return  Result.ok(BeanUtil.copyProperties(byId,SystemUserResponse.class));
    }



}
